var Tongkeyaopin = new Vue({
    el : "#Tongkeyaopinlist",
    data :{
        xiangmuId : $("#xiangmuId").val(),
        xiangmu : {},
        tongkeyaopin :{},
        tongkeyaopinlist : [],
        show : false,					// 显示列表是否有数据

        pageIndex : 1,
        pageSize :100,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",

    },

    created : function() {
        var _this = this;
        xiangmuId=_this.xiangmuId;
        _this.bindTongkeyaopinList();
        _this.bindXiangmu();

    },
    methods : {
        toback : function() {
            window.history.go(-1);
        },
        bindXiangmu:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid : _this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
        toDelete:function (){
            var _this = this;

            layer.confirm("确定删除该项目的材料吗？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});

                $.post("/tongkeyaopin/delete", {
                    xiangmuid : _this.xiangmuId,
                    random : Math.random()
                }, function(ppData) {
                    if (ppData != null) {
                        layer.closeAll("loading");

                        if(ppData.result != "1"){
                            layer.alert(ppData.message);
                        }else{
                            layer.open({
                                time:1000,
                                btn:[],
                                content:"删除成功!",
                            });

                            _this.bindTongkeyaopinList();
                            _this.bindXiangmu();
                        }
                    }
                },"json");
            })
        },

        bindTongkeyaopinList:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/tongkeyaopin/findtongkeyaopinlist",{
                xiangmuid : _this.xiangmuId,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                       "   <thead >\n" +
                       "    <tr style=\"font-weight: bold;\">\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;width:50px;\" rowspan=\"2\">序号</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >药品名称</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >规格</td>\n" +
                      /* "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >生产厂家</td>\n" +*/
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >单位</td>\n" +
                      /* "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >价格（元）</td>\n" +*/
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >医保类别</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" rowspan=\"2\" >基药</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\"colspan=\"5\" >建议保留条件</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" colspan=\"4\">建议淘汰条件</td>\n" +
                     /*  "        <td style=\"text-align:center;vertical-align:middle;\" colspan=\"2\">所在目录</td>\n" +*/
                       "        <td style=\"text-align:center;vertical-align:middle;\"colspan=\"2\" >半年内无采购记录</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\"rowspan=\"2\" >药剂科初选意见</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\"rowspan=\"2\">专家预选意见</td>\n" +
                    /*   "        <td style=\"text-align:center;vertical-align:middle;\"rowspan=\"2\">备注</td>\n" +*/
                       "    </tr>\n" +
                       "    <tr style=\"font-weight: bold;\">\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >集采药</td>\n" +
                     /*  "        <td style=\"text-align:center;vertical-align:middle;\" >通过一致性评价</td>\n" +*/
                       "        <td style=\"text-align:center;vertical-align:middle;\" >中药保密配方</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >国家中药保护</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >原国谈药</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >创新药</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >重点监控药</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >中药注射剂</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >严重不良反应</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >掉网药</td>\n" +
                    /*   "        <td style=\"text-align:center;vertical-align:middle;\" >院本部</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >秦淮</td>\n" +*/
                       "        <td style=\"text-align:center;vertical-align:middle;\" >院本部</td>\n" +
                       "        <td style=\"text-align:center;vertical-align:middle;\" >秦淮</td>\n" +
                       "    </tr>\n" ;
                        "    </thead>";
                   if(data.TongkeyaopinList.length > 0){
                       _this.show = true;
                       var PageInfo = data.PageInfo;
                       _this.pageIndex = PageInfo.pageIndex;
                       _this.recordCount = PageInfo.recordCount;
                       _this.pageCount = PageInfo.pageCount;

                       for (var i = 0; i < data.TongkeyaopinList.length; i++) {
                           var mmTongkeyaopin = data.TongkeyaopinList[i];
                           var mmXuhao = mmTongkeyaopin.xuhao;
                           var mmYaopinmingcheng = mmTongkeyaopin.yaopinmingcheng;
                           var mmShengchanchangjia=mmTongkeyaopin.shengchanchangjia;
                           var mmGuige = mmTongkeyaopin.guige;
                           var mmDanwei = mmTongkeyaopin.danwei;
                           var mmJiage = mmTongkeyaopin.jiage;
                           var mmYibaoleibie = mmTongkeyaopin.yibaoleibie;
                           var mmGuojiajibenyaowu = mmTongkeyaopin.guojiajibenyaowu;
                           var mmJicaiyao = mmTongkeyaopin.jicaiyao;
                           var mmTongguopingjia = mmTongkeyaopin.tongguopingjia;
                           var mmBaomipeifang = mmTongkeyaopin.baomipeifang;
                           var mmZhongyaobaohu = mmTongkeyaopin.zhongyaobaohu;
                           var mmYuanguotanyao = mmTongkeyaopin.yuanguotanyao;
                           var mmChuanxinyao = mmTongkeyaopin.chuanxinyao;
                           var mmJiankongyao = mmTongkeyaopin.jiankongyao;
                           var mmZhusheji = mmTongkeyaopin.zhusheji;
                           var mmBuliangfanying = mmTongkeyaopin.buliangfanying;
                           var mmDiaowangyao = mmTongkeyaopin.diaowangyao;
                           var mmDongzongyao = mmTongkeyaopin.dongzongyao;
                            var mmDongzongjilu2="";
                            if(mmTongkeyaopin.dongzongjilu2!=undefined){
                                var mmDongzongjilu2 = mmTongkeyaopin.dongzongjilu2;
                            }
                            var mmQinhuaiyao = mmTongkeyaopin.qinhuaiyao;

                            var mmQinhuaijilu2="";
                            if(mmTongkeyaopin.qinhuaijilu2!=undefined){
                                var mmQinhuaijilu2 = mmTongkeyaopin.qinhuaijilu2;
                            }
                            var mmZhuankefenzu = mmTongkeyaopin.zhuankefenzu;
                            var mmYuxuanyijian = mmTongkeyaopin.yuxuanyijian;
                            var mmBeizhu=mmTongkeyaopin.beizhu;

                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmXuhao + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmYaopinmingcheng + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmGuige + "'>" + mmGuige + "</a></td>";
                           /* mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmShengchanchangjia + "</td>";*/
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmDanwei + "</td>";
                       /*    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmJiage + "</td>";*/
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmYibaoleibie + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmGuojiajibenyaowu + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmJicaiyao + "</td>";
                           /* mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmTongguopingjia + "</td>";*/
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmBaomipeifang + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmZhongyaobaohu + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmYuanguotanyao + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmChuanxinyao + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmJiankongyao + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmZhusheji + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmBuliangfanying + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmDiaowangyao + "</td>";
                      /*      mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmDongzongyao + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmQinhuaiyao + "</td>";*/
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmDongzongjilu2 + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmQinhuaijilu2 + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmYuxuanyijian + "</td>";
                            mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmBeizhu + "</td>";
                          /*  mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + mmBeizhu + "</td>";*/
                            mmHtml += "</tr>";


                            }

                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },

    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.bindTongkeyaopinList();
        }
    }
});
